package msu.ml.core.xml;

import msu.ml.core.*;
import msu.ml.data.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;

/**
 * @author Reginald M Mead
 * @version 1.0
 */
public class DbcvDataProviderParser implements IDataProviderParser
{
   public IDataProvider parse(Element element)
   {
      String database = "nexrad";
      String user = "rmead";
      String pass = "";

      if(element.hasAttribute("db_name"))
         database = element.getAttribute("db_name");

      if(element.hasAttribute("db_user"))
         user = element.getAttribute("db_user");

      if(element.hasAttribute("db_pass"))
         pass = element.getAttribute("db_pass");

      DbcvDataProvider provider = 
         new DbcvDataProvider("jdbc:mysql://localhost/" 
               + database, user, pass);

      int folds = Integer.parseInt(element.getAttribute("folds"));
      provider.setNumFolds(folds);


      NodeList volumes = element.getElementsByTagName("volume");
      for(int i = 0; i < volumes.getLength(); i++)
         provider.addVolume(volumes.item(i).getTextContent());

      if(ApplicationSettings.getInstance().getConfig("verbose").equals("true"))
      {
         System.out.println("Dbcv Data Provider");
         System.out.println("\t Use " + folds + " folds");
      }

      return provider;
   }
}
